package com.tj.jinzao.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.tj.jinzao.R;
import com.tj.jinzao.base.BaseListAdapter;
import com.tj.jinzao.common.Constant;
import com.tj.jinzao.model.FollowFan;
import com.tj.jinzao.widgets.RoundedImageView;

import java.util.concurrent.CopyOnWriteArrayList;


/**
 * 我的粉丝 Adapter
 * Created by wjy on 2019/1/10.
 */
public class MyFansListItemAdapter extends BaseListAdapter<FollowFan, MyFansListItemAdapter.ViewHolder> {
private String mTag;
    public MyFansListItemAdapter(Context context, CopyOnWriteArrayList data,String mTag) {
        super(context, data);
        this.mTag=mTag;
    }

    private onClickLinstener mListener;

    public void setListener(onClickLinstener listener) {
        this.mListener = listener;
    }
    public interface onClickLinstener{
        void onClickAttent(long id);
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.item_fans_list, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        FollowFan user = mData.get(position);
        if(user!=null&&user.getFollowUser()!=null){
            holder.name.setText(user.getFollowUser().getNickname());
            holder.number.setText(user.getFollowUser().getCircleCount() + "篇日记 " + user.getFollowUser().getFans() + "个粉丝");
            Glide.with(mContext).load(Constant.IMAGE_PREFIX + user.getFollowUser().getImgurl()).into(holder.head);
        }else {
            holder.name.setText("");
            holder.number.setText( "0篇日记0个粉丝");
            holder.head.setImageResource(R.mipmap.default_head_women);
        }
        if(mTag.equals("2")){
            holder.follow.setText("已关注");
        }else {
            if(user.isMutualFans()){
                holder.follow.setText("已关注");
            }else {
                holder.follow.setText("关注");
            }

        }
        holder.follow.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(mListener!=null){
                    mListener.onClickAttent(user.getFollowUid());
                }
            }
        });
        holder.follow.setTag(R.id.position, position);
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        TextView name, number, follow;
        RoundedImageView head;

        public ViewHolder(View itemView) {
            super(itemView);
            name = itemView.findViewById(R.id.tv_name);
            number = itemView.findViewById(R.id.tv_number);
            follow = itemView.findViewById(R.id.tv_follow);
            head = itemView.findViewById(R.id.iv_head);

        }
    }


}
